package com.homwork.Collection_learn.List;

import java.util.Vector;

public class Vector_ {
    public static void main(String[] args) {
        //有参数构造器
        Vector vector = new Vector(8);
        for (int i = 0; i < 10; i++) {
            vector.add(i);
        }
        vector.add(100);
        /**
         * 解读
         * 1. new  Vector() 底层
         *
         *     public Vector() {
         *         this(10);
         *     }
         *   补充:如果是  Vector vector = new Vector(8);
         *   走的是
         *    public Vector(int initialCapacity, int capacityIncrement) {
         *         super();
         *         if (initialCapacity < 0)
         *             throw new IllegalArgumentException("Illegal Capacity: "+
         *                                                initialCapacity);
         *         this.elementData = new Object[initialCapacity];
         *         this.capacityIncrement = capacityIncrement;
         *     }
         *
         *

         *
         *
         * 2. vector.add(i)
         *
         * 2.1 //下面这个方法执行添加数据到Vector集合
         *   elementCount :现在数组中的数据
         *    public synchronized boolean add(E e) {
         *         modCount++;
         *         ensureCapacityHelper(elementCount + 1);
         *         elementData[elementCount++] = e;
         *         return true;
         *     }
         *
         *
         *
         * 2.2 确定是否需要扩容 添加关键条件 minCapacity - elementData.length > 0
         *
         *   private void ensureCapacityHelper(int minCapacity) {
         *         // overflow-conscious code
         *         if (minCapacity - elementData.length > 0)
         *             grow(minCapacity);
         *     }
         *
         *
         *
         *
         *  2.3      如果 需要的数组大小  不够用，就扩容，扩容算法
         *     int newCapacity = oldCapacity + ((capacityIncrement > 0) ?
         *          *                                          capacityIncrement : oldCapacity);
         *     就是扩容两倍
         *   private void grow(int minCapacity) {
         *         // overflow-conscious code
         *         int oldCapacity = elementData.length;
         *         int newCapacity = oldCapacity + ((capacityIncrement > 0) ?
         *                                          capacityIncrement : oldCapacity);
         *         if (newCapacity - minCapacity < 0)
         *             newCapacity = minCapacity;
         *         if (newCapacity - MAX_ARRAY_SIZE > 0)
         *             newCapacity = hugeCapacity(minCapacity);
         *         elementData = Arrays.copyOf(elementData, newCapacity);
         *     }
         *
         *
         *
         */
    }
}
